<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <title>添加区县</title>
    <link rel="stylesheet" href="/static/common/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/common/css/uploadpic.css">
    <link rel="stylesheet" href="/static/common/css/style.css">
    <link rel="stylesheet" href="/static/common/css/webuploader.css">
    <style type="text/css">
        .layui-upload-img {
            width: 92px;
            height: 92px;
            margin: 0 10px 10px 0;
        }

        .site-block {
            width: 80%;
            padding: 20px;
            border: 2px solid #eee;
        }

        .site-text {
            position: relative;
        }

        .title-location {
            font-size: 20px;
            font-weight: 600;
        }

        .rightlayer {
            display: inline-block;
        }

        .layui-input:focus, .layui-textarea:focus {
            border-color: red !important;
        }
    </style>
</head>
<body style="margin: 20px 20px ">
<div class="site-text site-block ">
    <form class="layui-form layui-form-pane " action="">
        <div class="layui-form-item">
            <label class="title-location">添加广告</label>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">位置</label>
            <div class="layui-input-block">
                <select name="advert_site" lay-verify="required" lay-filter="advert_site">
                    <option value="">请选择位置</option>
                <#list data as d>
                    <option value="${d.site_name}">${d.remark}</option>
                </#list>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">标题</label>
            <div class="layui-input-block">
                <input type="text" name="title" id="title" maxlength="30" lay-verify="required" placeholder="请输入标题(30字内)" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">访问URL</label>
            <div class="layui-input-block">
                <input type="text" name="access_path" id="access_path" maxlength="120" lay-verify="required|access_path" placeholder="请输入访问URL(120字内)  注意:必须  包含 http:// 或者 https//" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item " pane>
            <label class="layui-form-label" style="height: 180px!important;">楼盘封面图</label>
            <div class="layui-input-block" style="padding:  2px 2px 2px 15px;height: 180px!important;">
                <button type="button" class="layui-btn" id="test1">上传图片</button>
                <div class="layui-input-block">
                    <img class="layui-upload-img" id="demo1" style="margin: 4px -108px;">
                    <p id="demoText" style="margin: 4px -108px;"></p>
                </div>
                <input type="hidden" name="cover_img_path" value="" id="cover_img_path">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit="" lay-filter="formDemo">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</div>
</body>
<script type="text/javascript" src="/static/common/js/jquery-3.3.1.min.js"></script>
<script type="text/javascript" src="/static/common/layui/layui.js"></script>
<script type="text/javascript">
    layui.use('form', function () {
        var form = layui.form;
        //监听提交
        form.on('submit(formDemo)', function (data) {
            var cover_img_path = $("#cover_img_path").val();
            if (cover_img_path == null || cover_img_path == '' || cover_img_path == undefined) {
                layer.alert("还没有上传封面图!");
                return false;
            }
            $.post('/advert/details/insert.do', data.field, function (res) {
                if (res.data == true) {
                    layer.confirm('添加成功!是否要广告?', {icon: 1, title: '提示'}, function (index) {
                        window.location.href = '/advert/details/list.do';
                    });
                } else {
                    layer.alert("添加失败!", {icon: 2, title: '提示'});
                }
            });
            return false;
        });
        /*************************验证*****************************/
        form.verify({
            access_path: function (value) {
                if (value.indexOf("http://")==-1 && value.indexOf("https://")==-1) {
                    return '请正确输入URL';
                }
            }
        });
        /******************************************************/
    });
</script>
<script type="text/javascript">
    layui.use('upload', function () {
        var $ = layui.jquery
                , upload = layui.upload;
        //普通图片上传
        var uploadInst = upload.render({
            elem: '#test1',
            url: '/officeBuilding/building/upload.do',

            before: function (obj) {
                layer.msg('上传中...', {icon: 16, shade: 0.01});
                //预读本地文件示例，不支持ie8
                obj.preview(function (index, file, result) {
                    $('#demo1').attr('src', result); //图片链接（base64）
                });
            }
            , done: function (res) {
                //如果上传失败
                if (res.success == false) {
                    layer.closeAll('loading');
                    return layer.alert('上传失败');
                } else { //上传成功
                    var demoText = $('#demoText');
                    demoText.html('<span style="color: #01b84e;">上传成功</span>');
                    $("#cover_img_path").val(JSON.stringify(res.data));
                    layer.closeAll('loading');
                    return layer.alert('上传成功');
                }
            }
            , error: function () {
                //演示失败状态，并实现重传
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function () {
                    uploadInst.upload();
                });
            }
        });
    })
</script>
<script src="/static/common/js/ajaxhook.js" type="text/javascript"></script>
<script src="/static/common/js/ajaxHookData.js" type="text/javascript"></script>
</html>